const axios = require('axios');

// 测试队列服务的数据库操作功能
async function testDBQueue() {
    const queueServiceUrl = 'http://localhost:3003/api/queue/task';
    
    try {
        console.log('测试队列服务的数据库操作功能...');
        
        // 测试数据库查询操作
        console.log('1. 测试数据库查询操作...');
        const queryTask = {
            task: {
                type: 'db-query',
                sql: 'SELECT * FROM storage_slots LIMIT 5',
                params: []
            }
        };
        
        const queryResponse = await axios.post(queueServiceUrl, queryTask);
        console.log('查询任务提交成功:', queryResponse.data);
        
        // 测试数据库插入操作
        console.log('2. 测试数据库插入操作...');
        const insertTask = {
            task: {
                type: 'db-insert',
                sql: 'INSERT INTO TaskList (Task_No, Job_Style, Unload_Line, Unload_Col, Unload_Layer, is_issued) VALUES (?, ?, ?, ?, ?, ?)',
                params: [9999, 1, 1, 1, 1, 0]
            }
        };
        
        const insertResponse = await axios.post(queueServiceUrl, insertTask);
        console.log('插入任务提交成功:', insertResponse.data);
        
        // 测试数据库更新操作
        console.log('3. 测试数据库更新操作...');
        const updateTask = {
            task: {
                type: 'db-update',
                sql: 'UPDATE TaskList SET is_issued = ? WHERE Task_No = ?',
                params: [1, 9999]
            }
        };
        
        const updateResponse = await axios.post(queueServiceUrl, updateTask);
        console.log('更新任务提交成功:', updateResponse.data);
        
        // 测试数据库删除操作
        console.log('4. 测试数据库删除操作...');
        const deleteTask = {
            task: {
                type: 'db-delete',
                sql: 'DELETE FROM TaskList WHERE Task_No = ?',
                params: [9999]
            }
        };
        
        const deleteResponse = await axios.post(queueServiceUrl, deleteTask);
        console.log('删除任务提交成功:', deleteResponse.data);
        
        console.log('所有测试完成!');
        
    } catch (error) {
        console.error('测试失败:', error.message);
    }
}

testDBQueue();